﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>抽奖程序</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="../../Content/assets/css/admin/font.css">
    <link rel="stylesheet" href="../../Content/assets/lib/layui/css/layui.css">
    <link rel="stylesheet" href="../../Content/assets/css/admin/xadmin.css">
    <link rel="stylesheet" href="../../Content/assets/css/admin/Site.css">
    <link rel="stylesheet" href="../../Content/assets/css/admin/soulTable.css">

</head>
<body class="layui-anim layui-anim-up">
    <div class="x-body">
      <div class="layui-row actions">
        <form class="layui-form layui-col-md12 x-so">
                <div class="layui-input-inline">
                  <input type="text" id="fullname" name="fullname" placeholder="请输入姓名" autocomplete="off" class="layui-input search">
                </div>                     	
                <div class="layui-input-inline">
                  <input type="text" id="keywords" name="keywords" placeholder="是否参与" autocomplete="off" class="layui-input search">
                </div>
                <div class="layui-input-inline">
                  <input type="text" id="department" name="department" placeholder="部门" autocomplete="off" class="layui-input search">
                </div>
        <a class="layui-btn" data-type="reload"><i class="layui-icon">&#xe615;搜索</i></a>      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.reload();" title="刷新">
        <i class="layui-icon" style="line-height:30px">&#xe669;刷新</i></a>
            </form>    
      </div>
      <xblock class="actions">
        <button class="layui-btn layui-btn-danger" data-type="del"><i class="layui-icon"></i>删除</button>
        <button class="layui-btn" data-type="add"><i class="layui-icon"></i>添加</button>
      </xblock>
      <table  class="layui-hide" id="datalist" lay-filter="datalist"></table>
      <div id="page"></div>
              <script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">

  </div>
</script>
    </div>
			<script type="text/html" id="nameformate">
                <a href="#"  class="color-orange" onclick="update({{d.Identifier}})">{{d.FullName}}</a>				
			</script>
			<script type="text/html" id="imgformate">
                <a href="#"  class="color-orange" onclick="upload({{d.Identifier}})">上传</a>&nbsp{{#if (d.Avatar!=''){}}<a href="#"  class="color-orange" onclick="showimg('{{d.Avatar}}')">查看</a>{{#}}}				
			</script>
    <script type="text/javascript" src="../../Content/assets/js/jquery.min.js"></script>
    <script src="../../Content/assets/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../Content/assets/lib/xadmin.js"></script>
    <script type="text/javascript" src="../../Content/assets/lib/echarts.min.js"></script>
        <script>
            var controller='LotteryPerson';
            var params = '';
            var rmurl = '/' + controller + '/remove';//删除url
            var winwidth ='858';
            var winheight = '500';
            if (params == '') {
                params = '?rand=' + Math.random();
            } else {
                params = params + '&rand=' + Math.random();
            }
            function reloadtable() {
                console.log('reload');
                layui.table.reload("datatable", { url: '/'+controller+'/getEntity'+params });
            }
            /*添加*/
            function add(title, url, w, h) {
                xadmin.open(title, url, w, h);
                //xadmin.add_tab(title, url, true);
            }
            //编辑
            function update(id) {
                console.log(id);
                //add('编辑', '/' + controller + '/Edit?id=' + id, winwidth, winheight);
                //window.location = '/' + controller + '/Edit?id=' + id;
                window.open('/' + controller + '/Edit?id=' + id, '_blank');
            }

            function upload(id){
                add('导入', '/' + controller + '/Import?id='+id, winwidth, winheight);
            }

            function showimg(filename) {
                add('预览', '../Content/assets/icon/' + filename, winwidth, winheight);
            }
            // 自定义模块，这里只需要开放soulTable即可
            layui.config({
                base: '../../Content/assets/lib/layui/ext/',   // 模块目录
            }).extend({
                soulTable: 'soulTable'  // 模块别名
            });
            //JavaScript代码区域
            layui.use(['table', 'laydate', 'element', 'soulTable'], function () {
                var table = layui.table,
                    soulTable = layui.soulTable;
                //第一个实例
                var tableIns = table.render({
                    elem: '#datalist'
                    , height: 'full'
                    , cellMinWidth: 80
                    , url: '/'+controller+'/getEntity'+params //数据接口
                    , id: 'datatable'
                    , toolbar: '#toolbarDemo'
                    , totalRow: true//开启合计
                    , page: { //开启分页
                        limit: 50,
                        limits: [50, 100, 200, 300, 400, 500, 1000]
                    }
                    , cols: [[ //表头
                        { type: 'checkbox' }
                        , { type: 'numbers', title: '序号' }
                        , { field: 'Identifier', title: 'ID' }
                        , { field: 'FullName', title: '参与者姓名', templet:'#nameformate' }
                        , { field: 'Avatar', title: '头像图片', templet:'#imgformate' }
                        , { field: 'Company', title: '公司' }
                        , { field: 'Department', title: '部门' }
                        , { field: 'Phone', title: '电话号码' }
                        , { field: 'IsParticipator', title: '是否参与 默认是不参与=2 参与=1' }
                        , { field: 'AddDate', title: '添加时间', templet: '#dateformate' }
                        , { field: 'AddUser', title: '添加用户' }
                        , { field: 'SignInTime', title: '签到时间', templet: '#dateformate' }

                     ]]
                    , filter: {
                        items: ['column', 'clearCache'] // 加入了清除缓存按钮
                        ,cache: true
                        ,bottom: false
                    }
                    , done: function () {
                        soulTable.render(this);
                    }
                });
                //数据处理
                var $ = layui.$, active = {
                    change: function () { //编辑
                        var checkStatus = table.checkStatus('datatable')
                      , data = checkStatus.data;

                        if (data.length > 0) {
                            if (data.length > 1) {
                                layer.alert("选择一条进行编辑");
                                return false;
                            }
                            add('编辑', '/'+controller+'/Edit?id=' + data[0], winwidth, winheight);
                        }

                    }
                    , del: function () { //获取选中数目
                        var checkStatus = table.checkStatus('datatable')
                      , data = checkStatus.data;
                        console.log(JSON.stringify(data));
                        layer.confirm('确认要删除吗？', function (index) {
                            data.car_models = '';
                            //捉到所有被选中的，发异步进行删除
                            $.post(rmurl, { data: JSON.stringify(data) }, function (result) {
                                if (result.status) {
                                    layer.alert("删除成功", { icon: 6 });
                                    table.reload("datatable", { url: '/'+controller+'/getEntity' });

                                } else {
                                    layer.alert(result.message);
                                }
                            }, 'json');
                        });

                    }
                    , add: function () { //验证是否全选
                        add('添加', '/'+controller+'/Edit', winwidth, winheight);
                        //xadmin.add_tab('编辑', '/' + controller +'/Edit', true);
                    }
                    , sync: function () { //验证是否全选
                        synchronization();
                    }
                    , upload: function () { //验证是否全选
                        add('导入', '/' + controller + '/Import', winwidth, winheight);
                    }
                    , output: function () { //导出excel
                        output();
                    }
                    , reload: function () {
                        //执行重载
                        table.reload('datatable', {
                            page: {
                                curr: 1 //重新从第 1 页开始
                            }
                            , where: {
                                fullname: $('#fullname').val(),
                                IsParticipator: $('#keywords').val(),
                                department: $('#department').val(),
                            }
                        });
                    }
                    , back: function () {
                        window.location = '/'+controller+'/Index'+params;
                    }
                    ,updatenew:function(){
                        updatenew();
                    }                                     
                };

                $('.actions .layui-btn').on('click', function () {
                    var type = $(this).data('type');
                    active[type] ? active[type].call(this) : '';
                });
            });
            $(document).on('click', '.layui-table-view .layui-table-body tr', function (event) {
                var trElem = $(this);
                var tableView = trElem.closest('.layui-table-view');
                tableView.find('.layui-table-body tr.table_tr_click').removeClass('table_tr_click');
                tableView.find('.layui-table-body tr[data-index="' + trElem.data('index') + '"]').addClass('table_tr_click');
            });
        </script>
</body>
</html>
